package com.zs.propertymanage.controller;

import com.zs.propertymanage.annotation.SystemLog;
import com.zs.propertymanage.dataObj.R;
import com.zs.propertymanage.dataObj.workorderExtra.WorkOrderCategoryFlow;
import com.zs.propertymanage.service.impl.WorkOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/workorder")
@CrossOrigin
public class WorkOrderController {

    @Autowired
    private WorkOrderService workOrderService;

    /********  查询工单  ********/
    // 根据id查询工单
    @GetMapping("/{workOrderId}")
    @ResponseBody
    public R getWorkOrderById(@PathVariable String workOrderId) {
        return workOrderService.getWorkOrderById(workOrderId);
    }

    // 查询所有工单
    @GetMapping("")
    @ResponseBody
    public R getAllWorkOrder(String search, Integer currentPage, Integer pageSize) {
        return workOrderService.getAllWorkOrder(search, currentPage, pageSize);
    }

    /********  查询工单处理信息  ********/
    // 获取工单的处理信息
    @GetMapping("/handleInfo/{workOrderId}")
    @ResponseBody
    public R getHandleInfo(@PathVariable String workOrderId) {
        return workOrderService.getHandleInfo(workOrderId);
    }

    /********  工单状态、关闭状态  ********/
    // 查询所有工单状态
    @GetMapping("/status")
    @ResponseBody
    public R getAllWorkOrderStatus() {
        return workOrderService.getAllWorkOrderStatus();
    }

    // 添加工单状态
    @PostMapping("/status")
    @ResponseBody
    @SystemLog(name = "添加工单状态")
    public R addWorkOrderStatus(String statusName) {
        return workOrderService.addWorkOrderStatus(statusName);
    }

    // 删除工单状态
    @DeleteMapping("/status/{id}")
    @ResponseBody
    @SystemLog(name = "删除工单状态")
    public R deleteWorkOrderStatus(@PathVariable Integer id) {
        return workOrderService.deleteWorkOrderStatus(id);
    }

    // 租户更改关单状态 0-重新打开 1-关闭
    @PutMapping("/switchCloseStatus/{workOrderId}")
    @ResponseBody
    @SystemLog(name = "租户更改关单状态")
    public R switchCloseStatus(@PathVariable String workOrderId) {
        return workOrderService.switchCloseStatus(workOrderId);
    }

    /********  工单分类  ********/
    // 查询所有工单分类
    @GetMapping("/category")
    @ResponseBody
    public R getAllCategory() {
        return workOrderService.getAllCategory();
    }

    // 添加工单分类
    @PostMapping("/category")
    @ResponseBody
    @SystemLog(name = "添加工单分类")
    public R addCategory(String categoryName) {
        return workOrderService.addCategory(categoryName);
    }

    // 删除工单分类
    @DeleteMapping("/category/{id}")
    @ResponseBody
    @SystemLog(name = "删除工单分类")
    public R deleteCategory(@PathVariable Integer id) {
        return workOrderService.deleteCategory(id);
    }

    // 获取工单分类的职责人员 /category/duty
    @GetMapping("/category/duty/{categoryId}")
    @ResponseBody
    public R getCategoryDuty(@PathVariable Integer categoryId) {
        return workOrderService.getCategoryDuty(categoryId);
    }

    // 更新工单分类的职责人员
    @PutMapping("/category/duty/{categoryId}")
    @ResponseBody
    @SystemLog(name = "更新工单分类的职责人员")
    public R updateDuty(@PathVariable Integer categoryId, @RequestBody String[] duty) {
        return workOrderService.setCategoryDuty(categoryId, duty);
    }

    // 为工单分类设置流程
    @PostMapping("/category/flow")
    @ResponseBody
    @SystemLog(name = "为工单分类设置流程")
    public R setCategoryFlow(@RequestBody WorkOrderCategoryFlow flow) {
        return workOrderService.setCategoryFlow(flow);
    }

}
